﻿using System;
using System.Runtime.InteropServices;

namespace TypePrint
{
    class Program
    {
        static void Main()
        {
            // 输出第一行列信息
            Console.WriteLine("{0,-8} {1,8} {2,40} {3,40}", "类型名称", "字节数", "最小值", "最大值");

            PrintTypeInfo<sbyte>("sbyte");
            PrintTypeInfo<byte>("byte");
            PrintTypeInfo<short>("short");
            PrintTypeInfo<ushort>("ushort");
            PrintTypeInfo<int>("int");
            PrintTypeInfo<uint>("uint");
            PrintTypeInfo<long>("long");
            PrintTypeInfo<ulong>("ulong");
            PrintTypeInfo<float>("float");
            PrintTypeInfo<double>("double");
            PrintTypeInfo<decimal>("decimal");
        }

        //输出字节类型的具体信息函数
        static void PrintTypeInfo<T>(string typeName) where T : struct
        {
            //字节数
            int size = Marshal.SizeOf(typeof(T));
            //最小值和最大值
            object min = typeof(T).GetField("MinValue").GetValue(null);
            object max = typeof(T).GetField("MaxValue").GetValue(null);

            Console.WriteLine("{0,-8} {1,14} {2,44} {3,43}",
                              typeName, size, min, max);
        }
    }
}